package com.dehui.traders.ui.market.broader;

import android.content.Context;

import com.dehui.traders.bean.BaseListResponse;
import com.dehui.traders.bean.IndexInfo;
import com.dehui.traders.service.CallListener;
import com.dehui.traders.service.NetImpl;
import com.dehui.traders.ui.market.broader.TheBroaderMarketFragment;

import java.util.List;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import retrofit2.Call;
import retrofit2.Response;

/**
 * Created by hqq on 18.4.2.
 */

public class TheBroaderMarketViewModel extends BaseViewModel{

    public TheBroaderMarketFragment fragment;

    public TheBroaderMarketViewModel(Context context, TheBroaderMarketFragment fragment) {
        super(context);
        this.fragment = fragment;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        getIndex();
    }

    public void getIndex() {

        Call<BaseListResponse<IndexInfo>> call = NetImpl.realtimeQuotes("1");
        call.enqueue(new CallListener<BaseListResponse<IndexInfo>>() {
            @Override
            public void _onResponse(Response<BaseListResponse<IndexInfo>> response) {
                fragment.completeRefresh();
                BaseListResponse<IndexInfo> indexInfoBaseResponse = response.body();
                int status = indexInfoBaseResponse.status;
                if(status == 200){
                    List<IndexInfo> list = indexInfoBaseResponse.result;
                    fragment.updataList(list);
                }
            }

            @Override
            public void _onFailure() {
                fragment.completeRefresh();
            }
        });

    }


}
